package org.example.redisexamples.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.FunctionMode;
import org.redisson.api.FunctionResult;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.IntegerCodec;
import org.redisson.client.codec.StringCodec;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wuwenjin
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ExpireService {
    private final RedissonClient client;

    public boolean expire(String key,int expire,int count){
        return client.getFunction(IntegerCodec.INSTANCE)
                .call(FunctionMode.WRITE,//类型
                        "expireAPI_28",//访问的函数名称（键的名称）
                        FunctionResult.BOOLEAN,//返回的类型
                        List.of(key),//keys
                        expire,count);//可变参数 args
    }
}
